package Structure.array;

/**
 * @author wang'ji'cheng
 * @date 2025/7/25
 */
public class ArrayDemo1 {
    /**
     * 数组的静态初始化
     * 格式：int [] arr = new int []{}
     * 简化格式： int [] arr = {}
     */
    public static void main(String[] args) {
        //存储整形
        int[] arr1 = {1,2,3,4};

        //存储double
        double[] arr2 = {2.1, 3.5, 3.6};

        //存储字符串/对象
        String[] arr3 = {"张三","李四"};

        //访问元素
        System.out.println(arr1[1]);

        System.out.println(arr2[2]);

        System.out.println(arr3[0]);

        //添加元素

        arr1[0]=5;

        System.out.println(arr1[0]);


        //遍历数组
        for (int i : arr1) {
            System.out.println(i);
        }

        //遍历求和
        int sum = 0;
        for (int i : arr1) {
            System.out.println(i);
            sum += i;
        }
        System.out.println(sum);



    }

}
